// import { Page } from "@/types/storeModule"
import { assign, cloneDeep } from 'lodash-es'

const state = {
    // 接口调用参数
    params: {
        page: {
            currentPage: 1,
            pageSize: 20,
            totalCount: 0,
            totalPage: 0,
            sortField: 't.update_time',
            order: 'desc'
        },
        options: {}
    },
    roles: {}, // 权限
    apiName: 'trophy',
    privileges: ['admin-trophy-add', 'admin-trophy-add', 'admin-trophy-remove'],
    // 列表data数据
    isLoading: false,
    tableData: [],
    searchData: [
        {
            id: 'keyword',
            name: '机构名称或奖项',
            type: 'text',
            hint: '机构名称或奖项',
            defaultValue: ''
        },
        {
            id: 'entity.trophyStatus',
            name: '流程状态',
            type: 'select',
            hint: '流程状态',
            options: [
                {
                    key: '1',
                    value: '未申请'
                },
                {
                    key: '2',
                    value: '已申请'
                },
                {
                    key: '3',
                    value: '待制作'
                },
                {
                    key: '4',
                    value: '待审核'
                },
                {
                    key: '5',
                    value: '已完成'
                }
            ]
        }
    ],
    tableHeadList: [
        {
            label: '榜单年度',
            prop: 'rankYear',
            width: 60,
            slotName: 'rankYear'
        },
        {
            label: '申请时间',
            prop: 'createTime',
            width: 100
        },
        {
            label: '榜单发布时间',
            prop: 'rankPublishDate',
            width: 80,
            slotName: 'rankPublishDate'
        },
        {
            label: '申请机构',
            prop: 'researchOrgName',
            width: 120
        },
        {
            label: '获得奖项',
            prop: 'rankNames',
            width: 120,
            slotName: 'rankNames'
        },
        {
            label: '流程状态',
            prop: 'trophyStatus',
            width: 60,
            slotName: 'trophyStatus'
        },
        {
            label: '下载状态',
            prop: 'download',
            width: 60,
            slotName: 'download'
        }
    ]
}

// getters
const getters = {}

// actions
const actions = {}

// mutations
const mutations = {
    // 更新页面搜索内容
    updateSearchData(state, payload: any[]) {
        state.searchData = payload
    },
    // 更新表格 loading 状态
    updateLoading(state, payload: boolean) {
        state.isLoading = payload
    },

    // 更新数据page
    updatePage(state, payload: any) {
        state.params.page = assign(state.params.page, payload)
    },

    // 更新数据Condition
    updateCondition(state, payload: any) {
        state.params.condition = cloneDeep(payload)
    },

    // 更新data数据
    updateTableData(state, payload: any[]) {
        state.tableData = payload
    },
    // 更新列表表头数据
    updateEditTableList(state, payload: any[]) {
        state.tableHeadList = payload
    },
    // 更新列表参数数据
    updateParams(state, payload: any) {
        state.params = Object.assign({}, state.params, payload)
    },
    // 更新权限
    updateRoles(state, payload: Record<string, boolean>) {
        state.roles = payload
    }
}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}
